﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ECCIT.Security;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.BLL;
using ECCIT;

public partial class UpdatePwd : System.Web.UI.Page
{
    protected string guids;
    protected string userName;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(Request.QueryString["Guid"]))
        {
            Response.Redirect("/en/home.html");
        }
        else
        {
            guids = Request.QueryString["Guid"];
           IList<MemberModel> list= CheckGuid(guids);
           foreach (MemberModel model in list)
           {
               userName = model.Email;
           }
           this.TextBox1.Value = userName;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        
    }
    private bool ReSetPwd(string gid,string newPwd)
    {
        bool flag = false;
        IList<MemberModel> list = CheckGuid(gid);
        if (list.Count > 0)
        {
            foreach( MemberModel model in list)
            {
                newPwd = MD5Crypto.GetMD5Hash(newPwd);
                model.Password = newPwd;
                model.ForgetPwrdM = null;
                ResultInfo res = new MemberBLL(2052).Save(model);
                if (res.Result)
                {
                    flag = true;
                }
            }
        }
        return flag;
    }
    private IList<MemberModel> CheckGuid(string gid)
    {
        return new MemberBLL(2052).CheckGUid(gid);
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
        if (this.TextBox2.Value == this.TextBox3.Value)
        {
            if (ReSetPwd(guids, TextBox2.Value))
                Response.Write("<script>alert('重置成功');window.location.href=\"/en/home.html\"</script>");
        }
    }
}